package com.meizi.exception;

import com.meizi.enums.ErrorCodeEnum;
import com.meizi.utils.ErrorCodeUtils;

/**
 * @author Administration
 * @date 2021/8/18 - 16:29 - 星期三
 * @project lambda
 * @package com.meizi.utils
 * @by GGbomd猪猪侠
 */

/**
 * 自定义异常
 */
public class RenException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;

    public RenException() {
        this.code = ErrorCodeEnum.INTERNAL_SERVER_ERROR.getKey();
        this.msg = "未知错误";
    }

    public RenException(int code) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code);
    }

    public RenException(String msg, int code) {
        this.code = code;
        this.msg = msg;
    }

    public RenException(int code, String params) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code, params);
    }

    public RenException info(int code, String msg) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code, msg);
        return this;
    }

    public RenException(int code, String... params) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code, params);
    }

    public RenException(int code, Throwable e) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code);
    }

    public RenException(int code, Throwable e, String... params) {
        this.code = code;
        this.msg = ErrorCodeUtils.getMsg(code, params);
    }

    public RenException(String msg) {
        this.code = ErrorCodeEnum.INTERNAL_SERVER_ERROR.getKey();
        this.msg = msg;
    }

    public RenException(String msg, Throwable e) {
        this.code = ErrorCodeEnum.INTERNAL_SERVER_ERROR.getKey();
        this.msg = msg;
    }

    public String getMsg() {
        return this.msg;
    }

    public RenException setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public int getCode() {
        return this.code;
    }

    public RenException setCode(int code) {
        this.code = code;
        return this;
    }
}
